#include "nQueen.h"

nQueen::nQueen(int queenTotal):
  queenTotal(queenTotal),
  queensLine(new int[queenTotal]()),
  queensRow(new int[queenTotal]()){}

nQueen::~nQueen(){
    delete []queensRow;
    delete []queensLine;
}

int nQueen::calculate(){
    int result = 0;
    if(queenTotal < 1){
        return result;
    }
    queenPlaced = checkerRow = checkerLine = 0;
    while(queenPlaced > 0 || checkerLine == 0){
        if(isPlaceable()){
            queensLine[queenPlaced] = checkerLine;
            queensRow[queenPlaced] = checkerRow;
            ++queenPlaced;
            if(queenPlaced == queenTotal){
                ++result;
                back();
            }else{
                ++checkerLine;
                checkerRow = 0;
            }
        }else{
            moveNext();
        }
    }
    return result;
}
